home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Forms Misc / radio-quest-val.izs < prev    next >
Text File  |  2005-09-28  |  4KB  |  159 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Radio Question Validator 
  4. <!/TITLE>
  5.  
  6. <!DESCRIPTION>This script validates that every Radio Button question on the form has been answered. No modifications needed!<!/DESCRIPTION> 
  7.  
  8. <!CATEGORY>Forms<!/CATEGORY>
  9.  
  10. <!SCRIPT>
  11. <!-- START OF SCRIPT -->
  12.  
  13.  
  14. <!-- HOW TO INSTALL RADIO QUESTION VALIDATOR:
  15.  
  16.   1.  Copy code into the HEAD section of document
  17.   2.  Put last coding into the BODY section of document  -->
  18.  
  19. <!-- STEP ONE: Add code into HEAD section of document  -->
  20.  
  21. <HEAD>
  22.  
  23. <SCRIPT LANGUAGE="JavaScript">
  24.  
  25. <!-- Original:  David Blackledge -->
  26. <!-- Web Site:  http://David.Blackledge.com -->
  27.  
  28. <!-- Begin
  29. function checkRadios() {
  30.  var el = document.forms[0].elements;
  31.  for(var i = 0 ; i < el.length ; ++i) {
  32.   if(el[i].type == "radio") {
  33.    var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
  34.    var itemchecked = false;
  35.    for(var j = 0 ; j < radiogroup.length ; ++j) {
  36.     if(radiogroup[j].checked) {
  37.      itemchecked = true;
  38.      break;
  39.     }
  40.    }
  41.    if(!itemchecked) { 
  42.     alert("Please choose an answer for "+el[i].name+".");
  43.     if(el[i].focus)
  44.      el[i].focus();
  45.     return false;
  46.    }
  47.   }
  48.  }
  49.  return true;
  50. //  End -->
  51. </script>
  52.  
  53. </HEAD>
  54.  
  55. <!-- STEP TWO: Add code into BODY section of document  -->
  56.  
  57. <BODY>
  58.  
  59. <FORM onsubmit="return checkRadios(this);">
  60. Blue:
  61. <input type="radio" value="1" name="blue">
  62. <input type="radio" value="2" name="blue">
  63. <input type="radio" value="3" name="blue">
  64. <input type="radio" value="4" name="blue">
  65. <input type="radio" value="5" name="blue">
  66. <BR>
  67.  
  68. Red:
  69. <input type="radio" value="1" name="red">
  70. <input type="radio" value="2" name="red">
  71. <input type="radio" value="3" name="red">
  72. <input type="radio" value="4" name="red">
  73. <input type="radio" value="5" name="red">
  74. <BR>
  75.  
  76. <input type="submit" value="check" name="button">
  77. </FORM>
  78.  
  79.  
  80. <!-- END OF SCRIPT -->
  81. <!/SCRIPT>
  82.  
  83. <!PREVIEW>
  84. <!-- START OF SCRIPT -->
  85.  
  86.  
  87. <!-- HOW TO INSTALL RADIO QUESTION VALIDATOR:
  88.  
  89.   1.  Copy code into the HEAD section of document
  90.   2.  Put last coding into the BODY section of document  -->
  91.  
  92. <!-- STEP ONE: Add code into HEAD section of document  -->
  93.  
  94. <HEAD>
  95.  
  96. <SCRIPT LANGUAGE="JavaScript">
  97.  
  98. <!-- Original:  David Blackledge -->
  99. <!-- Web Site:  http://David.Blackledge.com -->
  100.  
  101. <!-- Begin
  102. function checkRadios() {
  103.  var el = document.forms[0].elements;
  104.  for(var i = 0 ; i < el.length ; ++i) {
  105.   if(el[i].type == "radio") {
  106.    var radiogroup = el[el[i].name]; // get the whole set of radio buttons.
  107.    var itemchecked = false;
  108.    for(var j = 0 ; j < radiogroup.length ; ++j) {
  109.     if(radiogroup[j].checked) {
  110.      itemchecked = true;
  111.      break;
  112.     }
  113.    }
  114.    if(!itemchecked) { 
  115.     alert("Please choose an answer for "+el[i].name+".");
  116.     if(el[i].focus)
  117.      el[i].focus();
  118.     return false;
  119.    }
  120.   }
  121.  }
  122.  return true;
  123. //  End -->
  124. </script>
  125.  
  126. </HEAD>
  127.  
  128. <!-- STEP TWO: Add code into BODY section of document  -->
  129.  
  130. <BODY>
  131.  
  132. <FORM onsubmit="return checkRadios(this);">
  133. Blue:
  134. <input type="radio" value="1" name="blue">
  135. <input type="radio" value="2" name="blue">
  136. <input type="radio" value="3" name="blue">
  137. <input type="radio" value="4" name="blue">
  138. <input type="radio" value="5" name="blue">
  139. <BR>
  140.  
  141. Red:
  142. <input type="radio" value="1" name="red">
  143. <input type="radio" value="2" name="red">
  144. <input type="radio" value="3" name="red">
  145. <input type="radio" value="4" name="red">
  146. <input type="radio" value="5" name="red">
  147. <BR>
  148.  
  149. <input type="submit" value="check" name="button">
  150. </FORM>
  151.  
  152.  
  153. <!-- END OF SCRIPT -->
  154. <!/PREVIEW>
  155.  
  156. <!RELATED>NONE<!/RELATED>
  157.